var app = getApp()
var util = require('../../utils/util.js')
var md5 = require('../md5.js');
Page({
  data: {
    content:''
  },
  submit: function () {
    this.setData({
      showModal: true
    })
  },
  onPullDownRefresh: function(){
    wx.stopPullDownRefresh({
      complete: (res) => {},
    });
  },
  //底部导航跳转
  toAiIndex: function () {
    util.toAiIndex()
  },
  toContactsIng: function () {
    util.toContactsIng()
  },
  toProductRevision: function () {
    util.toProductRevision()
  },
  toMy: function () {
    util.toMy()
  },
  toBadge: function () {
    util.toBadge()
  },
  preventTouchMove: function () {

  },
  getVal: function (e) {
    var mesg = e.detail.value
    this.setData({
      content: mesg
    })
  },

  go: function () {
    this.setData({
      showModal: false
    })
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    //设置语言0:中文，1：英文
    var setlanguage = wx.getStorageSync('setlanguage')
    if ((wx.getStorageSync('setlanguage') || !"".trim() == wx.getStorageSync('setlanguage'))) {
      this.setData({
        setlanguage: wx.getStorageSync('setlanguage')
      })
      if (setlanguage == 1) {
        wx.setNavigationBarTitle({
          title: 'Feedback'
        })
      } else {
        wx.setNavigationBarTitle({
          title: '意见反馈'
        })
      }
    } else {
      wx.setStorageSync('setlanguage', 0);
      this.setData({
        setlanguage: 0
      })
    }
    //获取缓存展会id和用户id存在则获取最新联系人列表
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
      && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
      //默认最新（调用pico接口）
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var url = app.globalData.picoaddress + '/attendee/user/profile'
      var k = {}
      k["v"] = '1.0.0'
      k["client"] = 'ios'
      k["timestamp"] = timestamp
      k["lan"] = 'cn'
      k["exhibitionid"] = exhibitionid
      k["u"] = u

      var sign = app.globalData.picotoken + 'clientiosexhibitionid' + exhibitionid + 'timestamp' + timestamp + app.globalData.picotoken
      console.log(sign)
      var curb64 = md5.hexMD5(sign)
      console.log(curb64)
      k["sign"] = curb64
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data
          that.setData({
            myMesg: curdata
          });
        }, fail: res => {
          console.log(res, "error")
        }

      })

      //获取头像
      var url1 = app.globalData.picoaddress + '/Attendee/user/getdeviceid'
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        url: url1,
        method: 'post',
        data: k,
        success(res) {
          console.log(res)
          var mesg = res.data
          console.log('mesg=' + mesg)
          var curdata = mesg.data
          that.setData({
            grMesg: curdata
          });
        }, fail: res => {
          console.log(res, "error")
        }

      })

    } else {
      wx.redirectTo({
        url: '../signInbyPhone/signIn'
      })
    }
    
  },
  yjfk: function () {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    //设置语言0:中文，1：英文
    var content = that.data.content
    var setlanguage = wx.getStorageSync('setlanguage')
    if ((wx.getStorageSync('setlanguage') || !"".trim() == wx.getStorageSync('setlanguage'))) {
      this.setData({
        setlanguage: wx.getStorageSync('setlanguage')
      })
    } else {
      wx.setStorageSync('setlanguage', 0);
      this.setData({
        setlanguage: 0
      })
    }
    //获取缓存展会id和用户id存在则获取最新联系人列表
    var exhibitionid = wx.getStorageSync('exhibitionid')
    var u = wx.getStorageSync('u')
    console.log('exhibitionid=' + exhibitionid)
    console.log('u=' + u)
    if ((content || !"".trim() == content)){
      if ((wx.getStorageSync('exhibitionid') || !"".trim() == wx.getStorageSync('exhibitionid'))
        && (wx.getStorageSync('u') || !"".trim() == wx.getStorageSync('u'))) {
        //默认最新（调用pico接口）
        var timestamp = Date.parse(new Date());
        timestamp = timestamp / 1000;
        var url = app.globalData.picoaddress + '/attendee/user/feedback'
        var k = {}
        k["v"] = '1.0.0'
        k["client"] = 'ios'
        k["timestamp"] = timestamp
        k["lan"] = 'cn'
        k["exhibitionid"] = exhibitionid
        k["u"] = u
        k["content"] = content
        var sign = app.globalData.picotoken + 'clientios' + 'content' + content + 'exhibitionid' + exhibitionid + 'timestamp' + timestamp + app.globalData.picotoken
        console.log(sign)
        var curb64 = md5.hexMD5(sign)
        console.log(curb64)
        k["sign"] = curb64
        wx.request({
          header: {
            'content-type': 'application/x-www-form-urlencoded',
          },
          url: url,
          method: 'post',
          data: k,
          success(res) {
            wx.showToast({
              title: '反馈成功',
              icon: 'success',
              duration: 2000
            })
            wx.navigateTo({
              url: '../my/my',
            })
          }, fail: res => {
            console.log(res, "error")
          }

        })

      } else {
        wx.redirectTo({
          url: '../signInbyPhone/signIn'
        })
      }
    }else{
      wx.showToast({
        title: '请输入反馈内容！',
        icon: 'success',
        duration: 2000
      })
    }
    
  },
})